<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<aside class="sidebar">
	<div class="fixed">
		<div class="widget widget-tabs">
			<ul class="nav nav-tabs" role="tablist">
				<li role="presentation" class="active">
					<a href="#notice" aria-controls="notice" role="tab" data-toggle="tab">网站公告</a>
				</li>
				<li role="presentation">
					<a href="#contact" aria-controls="contact" role="tab" data-toggle="tab">联系站长</a>
				</li>
			</ul>
			<div class="tab-content">
				<div role="tabpanel" class="tab-pane notice active" id="notice">
					<ul id="notice-tab">
						<!-- 公告显示栏 -->
					</ul>
				</div>
				<div role="tabpanel" class="tab-pane contact" id="contact">
					<h2>
						Email:
						<br />
						<a href="https://mail.qq.com/" data-toggle="tooltip" data-placement="bottom" title="https://mail.126.com/">tianjindong0804@126.com</a>
					</h2>
				</div>
			</div>
		</div>
		<div class="widget widget_search">
			 <form class="navbar-form"  method="post">
				<div class="input-group">
					<input type="text" name="keyword" class="form-control" size="35" placeholder="搜索功能暂未开放" maxlength="15" autocomplete="off" disabled="disabled">
					<span class="input-group-btn">
						<button class="btn btn-default btn-search" name="search" type="button">搜索</button>
					</span>
				</div>
			</form>
		</div>
	</div>
	<div class="widget widget_sentence">
		<h3>每日一句</h3>
		<div class="widget-sentence-content">
			<h4 id="dateInfo"></h4>
			<p>
				Do not let what you cannot do interfere with what you can do.
				<br />
				别让你不能做的事妨碍到你能做的事。（John Wooden）
			</p>
		</div>
	</div>
	<div class="widget widget_hot">
		<h3>热门文章</h3>
		<ul id="hot-article-list">
			<!-- 热门文章显示栏 -->
		</ul>
	</div>
</aside>

<script>
	$(function() {
		updateTime(); //显示当前时间
		loadNotice();//加载公告
		loadHotArticleList();//加载热门文章
	});
	function updateTime() {
		var date = new Date();
		var dateInfo = "";
		dateInfo += date.getFullYear() + "年";
		dateInfo += (date.getMonth() + 1) + "月";
		dateInfo += date.getDate() + "日  星期";
		var day = date.getDay();
		if (day == 0) {
			dateInfo += "天";
		} else if (day == 1) {
			dateInfo += '一';
		} else if (day == 2) {
			dateInfo += '二';
		} else if (day == 3) {
			dateInfo += '三';
		} else if (day == 4) {
			dateInfo += '四';
		} else if (day == 5) {
			dateInfo += '五';
		} else if (day == 6) {
			dateInfo += '六';
		}
		$("#dateInfo").append(dateInfo);
	}
	function loadNotice() { //加载公告
		$.post(
			"${pageContext.request.contextPath}/notice/index-list.action",
			function(data) {
				var list = data.list;
				var content = "";
				for (var i = 0; i < list.length; i++) {
					content += "<li><time datetime='" + list[i].stringUpdatetime + "'>" + list[i].briefUpdatetime + "</time><a href='/notice/"+list[i].id+".html' target='_blank'>" + list[i].briefTitle + "</a></li>";
				}
				if (data.count > 4) {//如果总条数超过4条，显示“更多公告”链接
					content+="<li><a href='/notice/list.html' target='_blank'>更多公告>></a></li>";
				}
				$("#notice-tab").append(content);
			},
			"json"
		);
	}
	
	//热门文章列表获取
	function loadHotArticleList(){
		$.post(
			"${pageContext.request.contextPath}/article/hot-list.action",
			{"countItem":5},//此处可以修改右部热门文章显示的条数
			function(data) {
				var list = data;
				var content = "";
				for (var i = 0; i < list.length; i++) {
					content += "<li><a href='${pageContext.request.contextPath}/article/"+list[i].category.alias+"/"+list[i].id+".html'><span class='thumbnail'></span><span class='text'>"+list[i].briefTitle+"</span><span class='muted'><i class='glyphicon glyphicon-time'></i> "+list[i].stringUpdatetime+"</span><span class='muted'><i class='glyphicon glyphicon-eye-open'></i>"+list[i].visitNum+"</span></a></li>";
				}
				$("#hot-article-list").append(content);
			},	
			"json"
		);
	}
</script>